package com.mikelouis.test.scala.proginscala.chapter2

/**
 * Created by yuazhu on 12/17/2014.
 */
object test {
  def main(args: Array[String]) {
    val msg = "Hello, World!"
    println(msg)

    val msg2: java.lang.String = "Hello again, world!"
    println(msg2)

    val msg3: String = "Hello yet again, world!"
    println(msg3)

    /** difference between val and var */
    // Scala有两种变量，val和var。val类似于Java里的final变量。一旦初始化了，val就不能再赋值了。与之对应的，var如同Java里面的非final变量。var可以在它生命周期中被多次赋值
    //    val msgToChange = "hello"
    var msgToChange = "hello"
    msgToChange = "Goodbye cruel world!"
    println(msgToChange)

    /** function test */
    var x = 10
    var y = 20
    println(max(x, y))

    x = 30
    y = 25
    println(max2(x, y))

    greet()
  }

  // def 函数名(括号中的参数列表): 函数返回值类型 = {大括号中的函数体...}
  def max(x: Int, y: Int): Int = {
    if (x > y) x
    else y
  }

  def max2(x: Int, y: Int) = if (x > y) x else y

  def greet() = println("Hello world")

}
